package com.example.neusoft215gdh.androidpro_21.Activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.neusoft215gdh.androidpro_21.Listener.UpdateListener;
import com.example.neusoft215gdh.androidpro_21.Model.UserModel;
import com.example.neusoft215gdh.androidpro_21.R;

public class UpdatePsdActivity extends AppCompatActivity implements View.OnClickListener,UpdateListener{

    EditText psd;
    Button queRen;
    String userid;
    String sessionid;
    String deDaopsd;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_update_psd);
        initView();
        queRen.setOnClickListener(this);
    }
    public  void initView(){
        psd= (EditText) findViewById(R.id.upPsd);
        queRen= (Button) findViewById(R.id.queRen);
        deDaopsd=psd.getText().toString();
    }

    @Override
    public void onClick(View v) {
        SharedPreferences user=getSharedPreferences("Userid",0);
        userid=user.getString("user_id","");
        sessionid=user.getString("sessionId","");
        switch (v.getId()){
            case R.id.queRen:
                UserModel userModel=new UserModel();
                userModel.updatePsd(sessionid,userid,deDaopsd,this);
                 break;
        }
    }

    @Override
    public void onFail(String msg) {

    }

    @Override
    public void onResponseUp(Integer integer) {
                if (integer==1){
                    Toast.makeText(UpdatePsdActivity.this, "更改成功!", Toast.LENGTH_SHORT).show();
                }
    }
}
